package com.mulanweb.api.module.controller.admin;

import com.jfinal.plugin.activerecord.Page;
import com.mulanweb.api.module.controller.BaseController;
import com.mulanweb.api.module.model.User;
import com.mulanweb.db.common.SQLGenerateHelper;
import com.mulanweb.validator.annotation.ValidateForm;

/**
 * Created by Administrator on 2016/11/8 0008.
 */
public class UserController extends BaseController{

    /**
     * 后台搜索用户
     */
    @ValidateForm
    public void search(){
        Long userId = getParaToLong("userId");
        Integer sex = getParaToInt("sex");
        String mobile_number = getPara("mobile_number");
        String wechat_nickname = getPara("wechat_nickname");
        SQLGenerateHelper helper = new SQLGenerateHelper("user","create_time desc") ;
        helper.addEqualsCondition("id",userId);
        helper.addEqualsCondition("sex",sex);
        helper.addEqualsCondition("mobile_number",mobile_number);
        helper.addLikeCondition("wechat_nickname",wechat_nickname);
        Page<User> page = User.dao.paginate(getParaToInt("PageNumber"),getParaToInt("PageSize"),helper.getSqlSelect(),helper.getSqlExceptSelect(),helper.getQueryParas());
        returnPageModelJson(page);
    }

    public void getDetail(){
        Long userId = getParaToLong("userId");
        renderJson(User.dao.findById(userId));
    }
}
